package com.example.yangjianquan.myapplication;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.widget.Toast;

/**
 * Created by yangjianquan on 2016/11/2.
 */

public class NetworkChangeReciver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {

        ConnectivityManager connectivityManager = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
        if (null!=networkInfo && networkInfo.isAvailable()){
            Toast.makeText(context,"网络可用！",Toast.LENGTH_SHORT).show();
        }else {
            Toast.makeText(context,"网络不可用！",Toast.LENGTH_SHORT).show();
        }

    }
}
